package cn.tedu.practice2303.LSS.day0412homework;



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;

public class Server1 {
    private ServerSocket serverSocket2;
    public Server1() {
        try {
            System.out.println("正在创建客户端...");
            serverSocket2 = new ServerSocket(10800);
            System.out.println("客户端已创建!");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void start2(){
        Socket socket2;
        try {
            System.out.println("客户端正在准备连接...");
            socket2 = serverSocket2.accept();
            System.out.println("一个客户端连接了");
            InputStream is = socket2.getInputStream();
            InputStreamReader isr = new InputStreamReader(is, StandardCharsets.UTF_8);
            BufferedReader br = new BufferedReader(isr);
            String line;
            while((line=br.readLine())!=null){
                System.out.println("客户端说:"+line);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    public static void main(String[] args) {
        Server1 server2 = new Server1();
        server2.start2();
    }
}
